<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>新增医生</title>
    <link href="/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>

<div class="container mt-5">
    <h2>新增医生</h2>
    <form id="addDoctorForm">
        <div class="mb-3">
            <label for="departmentId" class="form-label">科室ID</label>
            <input type="number" class="form-control" id="departmentId" name="departmentId" required>
        </div>
        <div class="mb-3">
            <label for="name" class="form-label">医生姓名</label>
            <input type="text" class="form-control" id="name" name="name" required>
        </div>
        <div class="mb-3">
            <label for="title" class="form-label">职称</label>
            <input type="text" class="form-control" id="title" name="title">
        </div>
        <div class="mb-3">
            <label for="description" class="form-label">描述</label>
            <textarea class="form-control" id="description" name="description"></textarea>
        </div>
        <div class="mb-3">
            <label for="workingDays" class="form-label">出诊日期</label>
            <input type="text" class="form-control" id="workingDays" name="workingDays" placeholder="如：周一,周三,周五">
        </div>
        <div class="row mb-3">
            <div class="col">
                <label for="morningStart" class="form-label">上午开始</label>
                <input type="time" class="form-control" id="morningStart" name="morningStart">
            </div>
            <div class="col">
                <label for="morningEnd" class="form-label">上午结束</label>
                <input type="time" class="form-control" id="morningEnd" name="morningEnd">
            </div>
        </div>
        <div class="row mb-3">
            <div class="col">
                <label for="afternoonStart" class="form-label">下午开始</label>
                <input type="time" class="form-control" id="afternoonStart" name="afternoonStart">
            </div>
            <div class="col">
                <label for="afternoonEnd" class="form-label">下午结束</label>
                <input type="time" class="form-control" id="afternoonEnd" name="afternoonEnd">
            </div>
        </div>
        <div class="mb-3">
            <label for="status" class="form-label">状态</label>
            <select class="form-select" id="status" name="status">
                <option value="1" selected>启用</option>
                <option value="0">禁用</option>
            </select>
        </div>
        <button type="submit" class="btn btn-success">提交</button>
    </form>
</div>

<script src="/js/jquery.min.js"></script>
<script>
    $(document).ready(function () {
        $('#addDoctorForm').on('submit', function (e) {
            e.preventDefault();

            const doctor = {
                departmentId: parseInt($('#departmentId').val()),
                name: $('#name').val(),
                title: $('#title').val(),
                description: $('#description').val(),
                workingDays: $('#workingDays').val(),
                morningStart: $('#morningStart').val(),
                morningEnd: $('#morningEnd').val(),
                afternoonStart: $('#afternoonStart').val(),
                afternoonEnd: $('#afternoonEnd').val(),
                status: parseInt($('#status').val())
            };

            $.ajax({
                url: "/admins/addDoctor",
                type: "POST",
                contentType: "application/json",
                data: JSON.stringify(doctor),
                success: function () {
                    alert("医生添加成功");
                    window.location.href = "/doctorList";
                },
                error: function () {
                    alert("添加失败");
                }
            });
        });
    });
</script>

</body>
</html>
